package com.Page.exam.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.Page.common.PageData;
import com.Page.exam.dao.TestquestionDAO;
import com.Page.exam.dao.TestOptionDAO;
import com.Page.exam.dto.QueryTestDomain;
import com.Page.exam.dto.TestDTO;
/**
 * 
* Copyright: Copyright (c) 2019 YancyChong.All rights reserved.
* 
* @ClassName: TestService.java
* @Description: 该类的功能描述
*
* @version: v1.0.0
* @author: YancyChong
* @date: 2019年5月15日 下午8:50:30 
*
* Modification History:
* Date         Author          Version            Description
*---------------------------------------------------------*
* 2019年5月15日     User           v1.0.0               修改原因
 */
@Service
@Transactional
public class TestService {

	@Autowired
	private TestquestionDAO testDao;
	
	@Autowired
	private TestOptionDAO testOptionDao;
	
	public TestDTO add(TestDTO testDto) {
		testDao.add1(testDto);
		testOptionDao.add(testDto.getId(), testDto.getOptions());
		return testDto;
	}
	
	@Transactional (readOnly = true)
	public TestDTO getById(String id) {
		TestDTO testDto = testDao.findById(id);
		if (null != testDto) {
			testDto.setOptions(testOptionDao.findByTestId(id));
		}
		return testDto;
	}
	
	public TestDTO update(TestDTO testDto) {
		testDao.update(testDto);
		testOptionDao.update(testDto.getId(), testDto.getOptions());
		return testDto;
	}
	
	public PageData<TestDTO> getTestPage(
			QueryTestDomain domain) {
		return testDao.getTestPage(domain);
	}
	
	public void delete(String id) {
		int c = testDao.delete(id);
		if (c > 0) {
			testOptionDao.delete(id);
		}
	}
}
